package org.windblog.core.servlet.option;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.windblog.core.OptionService;



@SuppressWarnings("serial")
public class DeleteOptionServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		
		String optionName = req.getParameter("option_name").trim();
		if(optionName==null || optionName.length()==0 ){
			req.setAttribute("error", "Must not empty!");
		}
		else if(!OptionService.exist(optionName))
			req.setAttribute("error", "This option name is not exist.");
		else
		{
			OptionService.deleteOption(optionName);
			req.setAttribute("msg", "Option deleted!");
			
		}
		ServletContext sc = getServletContext();
		RequestDispatcher rd = sc.getRequestDispatcher("/admin/options.jsp");   
	    rd.forward(req, resp);


	}
	
}